package com.trex.modules.tbl.replyform.service;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jeesite.common.config.Global;
import com.jeesite.modules.sys.utils.UserUtils;
import com.trex.modules.tbl.dao.TblXdLjzyjlDao;
import com.trex.modules.tbl.entity.ServerTrexConfig;
import com.trex.modules.tbl.entity.TblXdLjzyjl;
import com.trex.modules.tbl.lineform.dao.TblXdZxxdctzdDao;
import com.trex.modules.tbl.lineform.service.TblXdZxxdctzdService;
import com.trex.modules.tbl.service.TblXdLjzyjlService;
import com.trex.modules.tbl.workerplace.dao.TblZdWorkerdzDao;
import com.trex.modules.utils.JsonGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.trex.modules.tbl.replyform.entity.TblXdJxchsd;
import com.trex.modules.tbl.replyform.dao.TblXdJxchsdDao;

import static com.trex.modules.tbl.web.TblXdLjzyjlController.parseJsonToListOfMap;
import static com.trex.modules.utils.JsonGeneratorDetail.createJson;
import static com.trex.modules.utils.JsonSenderUtil.sendJsonWithHttpClient;
import static java.lang.Thread.sleep;

/**
 * 检修车回送单Service
 * @author jy
 * @version 2022-12-09
 */
@Service
public class TblXdJxchsdService extends CrudService<TblXdJxchsdDao, TblXdJxchsd> {
	@Autowired
	private TblXdJxchsdDao tblXdJxchsdDao;
	@Autowired
	private TblXdZxxdctzdDao tblXdZxxdctzdDao;
	@Autowired
	private TblZdWorkerdzDao tblZdWorkerdzDao;
	@Autowired
	private TblXdLjzyjlDao tblXdLjzyjlDao;


	private final ServerTrexConfig serverTrexConfig;

    public TblXdJxchsdService(ServerTrexConfig serverTrexConfig) {
        this.serverTrexConfig = serverTrexConfig;
    }

    /**
	 * 获取单条数据
	 *
	 * @param tblXdJxchsd
	 * @return
	 */
	@Override
	public TblXdJxchsd get(TblXdJxchsd tblXdJxchsd) {
		return super.get(tblXdJxchsd);
	}

	/**
	 * 查询分页数据
	 *
	 * @param tblXdJxchsd      查询条件
	 * @return
	 */
	@Override
	public Page<TblXdJxchsd> findPage(TblXdJxchsd tblXdJxchsd) {
		return super.findPage(tblXdJxchsd);
	}

	/**
	 * 查询列表数据
	 *
	 * @param tblXdJxchsd
	 * @return
	 */
	@Override
	public List<TblXdJxchsd> findList(TblXdJxchsd tblXdJxchsd) {

		if (tblXdJxchsd.getDqxlbh()!=null) {
			//管理
			return tblXdJxchsdDao.findList(tblXdJxchsd);
		} else {
			if (tblXdJxchsd.getRemark()!=null) {
				if (tblXdJxchsd.getRemark().equals("1")) {
					tblXdJxchsd.setRemark(null);
					//子查询
					return tblXdJxchsdDao.findList2(tblXdJxchsd.getLjzybh());
				} else if (tblXdJxchsd.getRemark().equals("3")) {
					tblXdJxchsd.setRemark(null);
					//列检调度
					return tblXdJxchsdDao.findList3(tblXdJxchsd);
				}
			}
			//查询
			return tblXdJxchsdDao.findList1(tblXdJxchsd);
		}

	}
	/**
	 * 保存数据（插入或更新）
	 *
	 * @param tblXdJxchsd
	 */
	@Override
	@Transactional
	public void save(TblXdJxchsd tblXdJxchsd) {
		super.save(tblXdJxchsd);
	}

	/**
	 * 更新检车人
	 *
	 * @param map
	 */
	@Transactional
	public Map<String, Object> updateMess(Map<String, Object> map) throws SQLException {
		tblXdJxchsdDao.updateMess(map);
		return map;
	}

	/**
	 * 确认
	 * 1列检调度确认 2 车站确认
	 *
	 * @param map
	 */
	@Transactional
	public Map<String, Object> confirmData(Map<String, Object> map) throws SQLException {
		tblXdJxchsdDao.confirmData(map);
		return map;
	}

	/**
	 * 撤销确认
	 * 1列检调度确认 2 车站确认
	 *
	 * @param map
	 */
	@Transactional
	public Map<String, Object> cancelData(Map<String, Object> map) throws SQLException {
		tblXdJxchsdDao.cancelData(map);
		return map;
	}

	/**
	 * 更新状态
	 *
	 * @param tblXdJxchsd
	 */
	@Override
	@Transactional
	public void updateStatus(TblXdJxchsd tblXdJxchsd) {
		super.updateStatus(tblXdJxchsd);
	}

	/**
	 * 删除数据
	 *
	 * @param
	 */
	@Transactional
	public void delete(HttpServletRequest request, String[] jhharray, String userId, String userName) {
		tblXdJxchsdDao.deleteById(jhharray, userId, userName);
	}


	public String findFaultName(String faultCode) {
		return tblXdJxchsdDao.findFaultName(faultCode);
	}

	public String findRepair(String repairMethodDetail) {
		return tblXdJxchsdDao.findRepair(repairMethodDetail);
	}

	public TblXdLjzyjl selectData(String ljzybh) {
		return tblXdJxchsdDao.selectData(ljzybh);
	}


	public TblXdJxchsd selectVehicleData(String s) {
		return tblXdJxchsdDao.selectVehicleData(s);
	}

	public void receiveData(String recId,
							String uuid,
							String wagonno,
							String wagonTypeCode,
							String wagonTypeName,
							String wagonGroupCode,
							String wagonGroupName,
							String stationCode,
							String station,
							String stationTime,
							String areaCode,
							String area,
							String yardnoCode,
							String yardno,
							String lineCode,
							String line,
							String sendStationCode,
							String sendStation,
							String arriveStationCode,
							String arriveStation,
							String focusArea,
							String goodsname,
							String isNoPeak,
							int seq) {
		tblXdJxchsdDao.receiveData(recId,
				uuid,
				wagonno,
				wagonTypeCode,
				wagonTypeName,
				wagonGroupCode,
				wagonGroupName,
				stationCode,
				station,
				stationTime,
				areaCode,
				area,
				yardnoCode,
				yardno,
				lineCode,
				line,
				sendStationCode,
				sendStation,
				arriveStationCode,
				arriveStation,
				focusArea,
				goodsname,
				isNoPeak,
		seq);
	}


	public void receiveInfo(JSONObject json) throws JsonProcessingException {
		ObjectMapper objectMapper = new ObjectMapper();

		// 使用 Jackson 将 JSON 解析为 Map
		Map<String, Object> parsedJson = objectMapper.readValue(json.toString(), Map.class);

		// 提取 "Tables" 中的 "BODY" 部分
		Map<String, List<Map<String, Object>>> tables = (Map<String, List<Map<String, Object>>>) parsedJson.get("Tables");
		List<Map<String, Object>> body = tables.get("BODY");
		String replace1 = UUID.randomUUID().toString().replace("-", "");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String format = formatter.format(date);
		for (Map<String, Object> jsonmap : body) {
			String checkFlag = jsonmap.get("CHECK_FLAG").toString();
			int i = tblXdZxxdctzdDao.selectCheckFlag(checkFlag);
			if (i != 0) {
				continue;
			}
			String replace = UUID.randomUUID().toString().replace("-", "");

			// 更新列检工作日志表数据
			tblXdZxxdctzdDao.receiveData(
					replace,
					replace1,
					"0",
					jsonmap.get("WAGONNO").toString(),
					jsonmap.get("DEVICE_NO").toString(),
					jsonmap.get("WAGON_GROUP_CODE").toString(),
					jsonmap.get("WAGON_GROUP_NAME").toString(),
					jsonmap.get("STATION_CODE").toString(),
					jsonmap.get("STATION").toString(),
					jsonmap.get("YARDNO_CODE").toString(),
					jsonmap.get("YARDNO").toString(),
					jsonmap.get("LINE_CODE").toString(),
					jsonmap.get("LINE").toString(),
					jsonmap.get("IS_NOPEAK").toString(),
					jsonmap.get("REPAIR_ORDER_NO").toString(),
					jsonmap.get("CHECK_FLAG").toString(),
					jsonmap.get("SEQ").toString(),
					format
			);

		}
	}

	@Transactional(rollbackFor = Exception.class)
	public void saveInfo(TblXdJxchsd tblXdJxchsd, HttpServletRequest request) throws Exception {
		String ids = tblXdJxchsd.getIds();
		String[] split = new String[0];
		if (tblXdJxchsd.getIds() != null && !tblXdJxchsd.getIds().trim().isEmpty()) {
			split = ids.split(",");
		} else {
			split = new String[]{tblXdJxchsd.getRecId()};
		}
		HashMap<String, Object> map = new HashMap<>();
		TblXdLjzyjl tblXdLjzyjl = selectData(tblXdJxchsd.getLjzybh());
		String[] replace = tblXdJxchsd.getRepairLineName().split(",");
		//实体类中无数据所以查数据库
		String JcrName = tblXdLjzyjlDao.selectJnrName(tblXdJxchsd.getJcrCode());
		String faultName = findFaultName(tblXdJxchsd.getFaultCode());
		String repairMethod = findRepair(tblXdJxchsd.getRepairMethodCode());
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String repairLineName = tblXdLjzyjlDao.selectRepairLineCode(replace[0]);
		String repairMethodDetailCode = tblXdJxchsdDao.selectRepairMethodDetail(tblXdJxchsd.getRepairMethodDetailCode());
		String userName = tblZdWorkerdzDao.selectName1(userId);
		tblXdJxchsd.setUserid(userId);
		tblXdJxchsd.setUserName(userName);
		tblXdJxchsd.setFaultName(faultName);
		tblXdJxchsd.setRepairMethod(repairMethod);
		String I_IP_ADDR = request.getRemoteHost(); // 取IP
		String I_USERCODE = UserUtils.getUser().getUserCode(); // 取用户id
		String I_USERNAME = UserUtils.getUser().getUserName(); //用户名

		map.put("I_JXCBH", tblXdJxchsd.getRecId());    // 检修车编号
		map.put("I_JCRCODE", tblXdJxchsd.getJcrCode());    // 检车人编号
		map.put("I_JCRNAME", tblXdJxchsd.getJcrName()); // 检车人名字

		map.put("I_SENDCODE", tblXdJxchsd.getSendStationCode()); // 发站编号
		map.put("I_SENDSTATION", tblXdJxchsd.getSendStation()); // 发站
		map.put("I_ARRIVECODE", tblXdJxchsd.getArriveStationCode()); // 到站编号
		map.put("I_ARRIVESTATION", tblXdJxchsd.getArriveStation()); // 到站
//		map.put("I_REPAIRLINECODE", replace[0]); //入修地点编码
//		map.put("I_REPAIRLINENAME", repairLineName); //入修地点

		map.put("I_REPAIRLINECODE", tblXdJxchsd.getRepairLineCode()); //入修地点编码
		map.put("I_REPAIRLINENAME", tblXdJxchsd.getRepairLineName()); //入修地点

		map.put("I_ISNOPEAK", tblXdJxchsd.getIsNopeak()); //是否禁峰
		map.put("I_FAULTITEMCODE", tblXdJxchsd.getFaultItemCode()); //扣车类别编码
		map.put("I_FAULTITEMNAME", tblXdJxchsd.getFaultItemName()); //扣车类别
		map.put("I_FAULTCODE", tblXdJxchsd.getFaultCode()); //扣车原因编码
		map.put("I_FAULTNAME", tblXdJxchsd.getFaultName()); //扣车原因

		map.put("I_REPAIRMETHODCODE", tblXdJxchsd.getRepairMethodCode()); //入修类别编码
		map.put("I_REPAIRMETHOD", repairMethod); //入修类别
		map.put("I_REPAIRMETHODDETAILCODE", tblXdJxchsd.getRepairMethodDetailCode()); //入修方式编码
		map.put("I_REPAIRMETHODDETAIL", repairMethodDetailCode); //入修方式

		map.put("I_SPEEDLIMIT", tblXdJxchsd.getSpeedLimit()); //限速
		map.put("I_REMARK", tblXdJxchsd.getRemark()); //备注
		map.put("I_USERCODE", userId); //登录用户
		map.put("I_USERNAME", userName); //登录用户
		map.put("I_IP", I_IP_ADDR); // 本机IP地址

		try {
			if (split == null) {
				Map<String, Object> stringObjectMap = updateMess(map);
				Object oFlag = stringObjectMap.get("O_FLAG");
			} else {
				for (String s : split) {
					map.put("I_JXCBH", s);
					Map<String, Object> stringObjectMap = updateMess(map);
					Object oFlag = stringObjectMap.get("O_FLAG");
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (String s : split) {
			tblXdJxchsd = selectVehicleData(s);
			String flag = map.get("O_FLAG").toString();
			if (flag.equals("0")) {
				long timestamp = System.currentTimeMillis();
				// 将时间戳转换为 Date 对象
				Date date = new Date(timestamp);

				// 使用 SimpleDateFormat 格式化时间戳为 yyyyMMddHHmmss 格式的字符串
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
				String formattedDate = sdf.format(date);
				String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
				// SysInfo 数据
				Map<String, Object> sysInfo2 = Map.of(
						"Flag", 0,
						"Msg", "",
						"SvcName", "NEM215",
						"Sender", "NE",
						"UUID", timestampWithLast4Millis
				);

				// BODY 表的 Columns 数据
				List<Map<String, String>> bodyColumns2 = List.of(
						Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
						Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
						Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "铁路车号"),
						Map.of("Name", "GOODS_CODE", "DataType", "S", "Caption", "运输品名"),
						Map.of("Name", "GOODS_NAME", "DataType", "S", "Caption", "运输品名名称"),
						Map.of("Name", "MAKE_GOODS_CODE", "DataType", "S", "Caption", "制造品名代码"),
						Map.of("Name", "MAKE_GOODS_NAME", "DataType", "S", "Caption", "制造品名名称"),
						Map.of("Name", "STATION_CODE", "DataType", "S", "Caption", "当前车站"),
						Map.of("Name", "STATION_NAME", "DataType", "S", "Caption", "车站名称"),
						Map.of("Name", "YARDNO", "DataType", "S", "Caption", "当前场地"),
						Map.of("Name", "YARDNO_CNAME", "DataType", "S", "Caption", "场地名称"),
						Map.of("Name", "STATION_TRACK", "DataType", "S", "Caption", "当前股道"),
						Map.of("Name", "STATION_TRACK_CNAME", "DataType", "S", "Caption", "股道中文"),
						Map.of("Name", "NOTIFIER", "DataType", "S", "Caption", "通知人"),
						Map.of("Name", "NOTICE_TIME", "DataType", "S", "Caption", "通知时间"),
						Map.of("Name", "CAR_INSPECTOR", "DataType", "S", "Caption", "检车人"),
						Map.of("Name", "WAGON_CHECK_PERSON", "DataType", "S", "Caption", "列检人"),
						Map.of("Name", "TRAIN_INSPECTE_STIME", "DataType", "S", "Caption", "列检开始时间"),
						Map.of("Name", "FS_CODE", "DataType", "S", "Caption", "发站代码TS"),
						Map.of("Name", "ARRI_STATION_CODE", "DataType", "S", "Caption", "到站代码"),
						Map.of("Name", "ARRI_STOCK", "DataType", "S", "Caption", "到达股道"),
						Map.of("Name", "DETAIN_CAR_TYPE", "DataType", "S", "Caption", "扣车类别代码"),
						Map.of("Name", "DETAIN_CAR_TYPE_CNAME", "DataType", "S", "Caption", "扣车类别名称"),
						Map.of("Name", "ERR_CAUSE_CODE", "DataType", "S", "Caption", "故障代码"),
						Map.of("Name", "FAULT_REASON", "DataType", "S", "Caption", "故障原因_1"),
						Map.of("Name", "IN_REPAIR_TYPE", "DataType", "S", "Caption", "入修类别"),
						Map.of("Name", "IN_REPAIR_WAY", "DataType", "S", "Caption", "入修方式"),
						Map.of("Name", "TRAIN_INSPECTE_ETIME", "DataType", "S", "Caption", "列检结束时间"),
						Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")

				);

				// BODY 表的 Rows 数据
				// 处理 tblXdJxchsd 对象
				String ljzybh = tblXdJxchsd != null ? tblXdJxchsd.getLjzybh() : "";
				String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
				Date workStartTime = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getWorkStartTime()).orElse(new Date()) : new Date();
				String faultItemCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemCode()).orElse("") : "";
				String faultItemName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemName()).orElse("") : "";
				String faultCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultCode()).orElse("") : "";
				faultName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultName()).orElse("") : "";
				String repairMethodCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodCode()).orElse("") : "";
				repairMethodDetailCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodDetailCode()).orElse("") : "";
				String remark = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRemark()).orElse("") : "";


// 处理 tblXdLjzyjl 对象
				String stationUsername = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationUsername()).orElse("") : "";
				Date stationTime = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationTime()).orElse(new Date()) : new Date();
				String lineCodeFirstTwo = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getArriveStationCode()).map(code -> code.length() >= 2 ? code.substring(0, 2) : "").orElse("") : "";
				String lineCode = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getRepairLineCode()).orElse("") : "";

// 构建 bodyRows2 列表
				List<List<Object>> bodyRows2 = List.of(
						List.of(
								"I",
								s,
								wagonno,
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								stationUsername,
								stationTime,
								JcrName,
								userName,
								workStartTime,
								"",
								lineCodeFirstTwo,
								lineCode,
								faultItemCode,
								faultItemName,
								faultCode,
								faultName,
								repairMethodCode,
								repairMethodDetailCode,
								"",
								remark
						)
				);


				//构建 Tables 数据
				List<Map<String, Object>> tables2 = List.of(
						Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2)
				);


				String json2 = createJson(sysInfo2, tables2);


				String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
				logger.info("####################################" + result);
			}
		}
	}



	@Transactional(rollbackFor = Exception.class)
	public void deleteInfo(String jhhString, HttpServletRequest request) throws Exception {
		String replace = jhhString.replace("^", ",");
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String[] jhharray = replace.split(",");
		long timestamp = System.currentTimeMillis();
		String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
		for (String s : jhharray) {
			TblXdJxchsd tblXdJxchsd = selectVehicleData(s);
			TblXdLjzyjl tblXdLjzyjl = selectData(tblXdJxchsd.getLjzybh());
			String JcrName = null;
			//实体类中无数据所以查数据库

			JcrName = tblXdLjzyjlDao.selectJnrName(tblXdLjzyjl.getJcrCode());

			// SysInfo 数据
			Map<String, Object> sysInfo2 = Map.of(
					"Flag", 0,
					"Msg", "",
					"SvcName", "NEM215",
					"Sender", "NE",
					"UUID", timestampWithLast4Millis
			);

			// BODY 表的 Columns 数据
			List<Map<String, String>> bodyColumns2 = List.of(
					Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
					Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
					Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "铁路车号"),
					Map.of("Name", "GOODS_CODE", "DataType", "S", "Caption", "运输品名"),
					Map.of("Name", "GOODS_NAME", "DataType", "S", "Caption", "运输品名名称"),
					Map.of("Name", "MAKE_GOODS_CODE", "DataType", "S", "Caption", "制造品名代码"),
					Map.of("Name", "MAKE_GOODS_NAME", "DataType", "S", "Caption", "制造品名名称"),
					Map.of("Name", "STATION_CODE", "DataType", "S", "Caption", "当前车站"),
					Map.of("Name", "STATION_NAME", "DataType", "S", "Caption", "车站名称"),
					Map.of("Name", "YARDNO", "DataType", "S", "Caption", "当前场地"),
					Map.of("Name", "YARDNO_CNAME", "DataType", "S", "Caption", "场地名称"),
					Map.of("Name", "STATION_TRACK", "DataType", "S", "Caption", "当前股道"),
					Map.of("Name", "STATION_TRACK_CNAME", "DataType", "S", "Caption", "股道中文"),
					Map.of("Name", "NOTIFIER", "DataType", "S", "Caption", "通知人"),
					Map.of("Name", "NOTICE_TIME", "DataType", "S", "Caption", "通知时间"),
					Map.of("Name", "CAR_INSPECTOR", "DataType", "S", "Caption", "检车人"),
					Map.of("Name", "WAGON_CHECK_PERSON", "DataType", "S", "Caption", "列检人"),
					Map.of("Name", "TRAIN_INSPECTE_STIME", "DataType", "S", "Caption", "列检开始时间"),
					Map.of("Name", "FS_CODE", "DataType", "S", "Caption", "发站代码TS"),
					Map.of("Name", "ARRI_STATION_CODE", "DataType", "S", "Caption", "到站代码"),
					Map.of("Name", "ARRI_STOCK", "DataType", "S", "Caption", "到达股道"),
					Map.of("Name", "DETAIN_CAR_TYPE", "DataType", "S", "Caption", "扣车类别代码"),
					Map.of("Name", "DETAIN_CAR_TYPE_CNAME", "DataType", "S", "Caption", "扣车类别名称"),
					Map.of("Name", "ERR_CAUSE_CODE", "DataType", "S", "Caption", "故障代码"),
					Map.of("Name", "FAULT_REASON", "DataType", "S", "Caption", "故障原因_1"),
					Map.of("Name", "IN_REPAIR_TYPE", "DataType", "S", "Caption", "入修类别"),
					Map.of("Name", "IN_REPAIR_WAY", "DataType", "S", "Caption", "入修方式"),
					Map.of("Name", "TRAIN_INSPECTE_ETIME", "DataType", "S", "Caption", "列检结束时间"),
					Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")

			);

			// BODY 表的 Rows 数据
			// 处理 tblXdJxchsd 对象
			String ljzybh = tblXdJxchsd != null ? tblXdJxchsd.getLjzybh() : "";
			String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
			Date workStartTime = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getWorkStartTime()).orElse(new Date()) : new Date();
			String faultItemCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemCode()).orElse("") : "";
			String faultItemName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemName()).orElse("") : "";
			String faultCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultCode()).orElse("") : "";
			String faultName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultName()).orElse("") : "";
			String repairMethodCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodCode()).orElse("") : "";
			String repairMethodDetailCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodDetailCode()).orElse("") : "";
			String remark = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRemark()).orElse("") : "";
// 处理 tblXdLjzyjl 对象
			String stationUsername = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationUsername()).orElse("") : "";
			Date stationTime = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationTime()).orElse(new Date()) : new Date();
			String lineCodeFirstTwo = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getArriveStationCode()).map(code -> code.length() >= 2 ? code.substring(0, 2) : "").orElse("") : "";
			String lineCode = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getRepairLineCode()).orElse("") : "";

// 构建 bodyRows2 列表
			List<List<Object>> bodyRows2 = List.of(
					List.of(
							"D",
							s,
							wagonno,
							"",
							"",
							"",
							"",
							"",
							"",
							"",
							"",
							"",
							"",
							stationUsername,
							stationTime,
							JcrName,
							userName,
							workStartTime,
							"",
							lineCodeFirstTwo,
							lineCode,
							faultItemCode,
							faultItemName,
							faultCode,
							faultName,
							repairMethodCode,
							repairMethodDetailCode,
							"",
							remark
					)
			);


			//构建 Tables 数据
			List<Map<String, Object>> tables2 = List.of(
					Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2)
			);


			String json2 = createJson(sysInfo2, tables2);

//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
			String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
			logger.info("####################################" + result);
			delete(request, jhharray, userId, userName);
		}


	}


	@Transactional(rollbackFor = Exception.class)
	public void confirmDataInfo(String ids, String type_LC, HttpServletRequest request) throws Exception {
		String I_IP_ADDR = request.getRemoteHost(); // 取IP
		String I_USERCODE = UserUtils.getUser().getUserCode(); // 取用户id
		String I_USERNAME = UserUtils.getUser().getUserName(); //用户名
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String jnrName = tblXdLjzyjlDao.selectJnrName(userId);
		String[] idN = ids.split(",");
		int type = 0;
		for (int i = 0; i < idN.length; i++) {

			HashMap<String, Object> map = new HashMap<>();
			map.put("I_JXCBH", idN[i]);    // rec_id
			map.put("I_FLAG", type_LC);    // /* 1列检调度确认 2 车站确认 */
			map.put("I_USERCODE", userId); //登录用户
			map.put("I_USERNAME", userName); //登录用户
			map.put("I_IP", I_IP_ADDR); // 本机IP地址
			try {
				confirmData(map);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			String flag = map.get("O_FLAG").toString();
			if (flag.equals("0")) {
				TblXdJxchsd tblXdJxchsd = selectVehicleData(idN[i]);
				TblXdLjzyjl tblXdLjzyjl = selectData(tblXdJxchsd.getLjzybh());
				String JcrName = tblXdLjzyjlDao.selectJnrName(tblXdLjzyjl.getJcrCode());
				long timestamp = System.currentTimeMillis();
				// 将时间戳转换为 Date 对象
				Date date = new Date(timestamp);

				// 使用 SimpleDateFormat 格式化时间戳为 yyyyMMddHHmmss 格式的字符串
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
				String formattedDate = sdf.format(date);
				String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
				// SysInfo 数据
				Map<String, Object> sysInfo2 = Map.of(
						"Flag", 0,
						"Msg", "",
						"SvcName", "NEM215",

						"Sender", "NE",
						"UUID", timestampWithLast4Millis
				);

				// BODY 表的 Columns 数据
				List<Map<String, String>> bodyColumns2 = List.of(
						Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
						Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
						Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "铁路车号"),
						Map.of("Name", "GOODS_CODE", "DataType", "S", "Caption", "运输品名"),
						Map.of("Name", "GOODS_NAME", "DataType", "S", "Caption", "运输品名名称"),
						Map.of("Name", "MAKE_GOODS_CODE", "DataType", "S", "Caption", "制造品名代码"),
						Map.of("Name", "MAKE_GOODS_NAME", "DataType", "S", "Caption", "制造品名名称"),
						Map.of("Name", "STATION_CODE", "DataType", "S", "Caption", "当前车站"),
						Map.of("Name", "STATION_NAME", "DataType", "S", "Caption", "车站名称"),
						Map.of("Name", "YARDNO", "DataType", "S", "Caption", "当前场地"),
						Map.of("Name", "YARDNO_CNAME", "DataType", "S", "Caption", "场地名称"),
						Map.of("Name", "STATION_TRACK", "DataType", "S", "Caption", "当前股道"),
						Map.of("Name", "STATION_TRACK_CNAME", "DataType", "S", "Caption", "股道中文"),
						Map.of("Name", "NOTIFIER", "DataType", "S", "Caption", "通知人"),
						Map.of("Name", "NOTICE_TIME", "DataType", "S", "Caption", "通知时间"),
						Map.of("Name", "CAR_INSPECTOR", "DataType", "S", "Caption", "检车人"),
						Map.of("Name", "WAGON_CHECK_PERSON", "DataType", "S", "Caption", "列检人"),
						Map.of("Name", "TRAIN_INSPECTE_STIME", "DataType", "S", "Caption", "列检开始时间"),
						Map.of("Name", "FS_CODE", "DataType", "S", "Caption", "发站代码TS"),
						Map.of("Name", "ARRI_STATION_CODE", "DataType", "S", "Caption", "到站代码"),
						Map.of("Name", "ARRI_STOCK", "DataType", "S", "Caption", "到达股道"),
						Map.of("Name", "DETAIN_CAR_TYPE", "DataType", "S", "Caption", "扣车类别代码"),
						Map.of("Name", "DETAIN_CAR_TYPE_CNAME", "DataType", "S", "Caption", "扣车类别名称"),
						Map.of("Name", "ERR_CAUSE_CODE", "DataType", "S", "Caption", "故障代码"),
						Map.of("Name", "FAULT_REASON", "DataType", "S", "Caption", "故障原因_1"),
						Map.of("Name", "IN_REPAIR_TYPE", "DataType", "S", "Caption", "入修类别"),
						Map.of("Name", "IN_REPAIR_WAY", "DataType", "S", "Caption", "入修方式"),
						Map.of("Name", "TRAIN_INSPECTE_ETIME", "DataType", "S", "Caption", "列检结束时间"),
						Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")
				);

				// BODY 表的 Rows 数据
				// 处理 tblXdJxchsd 对象
				String ljzybh = tblXdJxchsd != null ? tblXdJxchsd.getLjzybh() : "";
				String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
				Date workStartTime = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getWorkStartTime()).orElse(new Date()) : new Date();
				String faultItemCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemCode()).orElse("") : "";
				String faultItemName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemName()).orElse("") : "";
				String faultCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultCode()).orElse("") : "";
				String faultName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultName()).orElse("") : "";
				String repairMethodCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodCode()).orElse("") : "";
				String repairMethodDetailCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodDetailCode()).orElse("") : "";
				String remark = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRemark()).orElse("") : "";
// 处理 tblXdLjzyjl 对象
				String stationUsername = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationUsername()).orElse("") : "";
				Date stationTime = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationTime()).orElse(new Date()) : new Date();
				String lineCodeFirstTwo = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getArriveStationCode()).map(code -> code.length() >= 2 ? code.substring(0, 2) : "").orElse("") : "";
				String lineCode = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getRepairLineCode()).orElse("") : "";

// 构建 bodyRows2 列表
				List<List<Object>> bodyRows2 = List.of(
						List.of(
								"I",
								idN[i],
								wagonno,
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								stationUsername,
								stationTime,
								JcrName,
								userName,
								workStartTime,
								"",
								lineCodeFirstTwo,
								lineCode,
								faultItemCode,
								faultItemName,
								faultCode,
								faultName,
								repairMethodCode,
								repairMethodDetailCode,
								"",
								remark
						)
				);


				//构建 Tables 数据
				List<Map<String, Object>> tables2 = List.of(
						Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2)
				);


				String json2 = createJson(sysInfo2, tables2);


//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
				String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
				logger.info("####################################" + result);

				sleep(1000);
				// SysInfo 数据
				Map<String, Object> sysInfo = Map.of(
						"Flag", 0,
						"Msg", "",
						"SvcName", "NEM216",
						"UUID", timestampWithLast4Millis
				);

				// BODY 表的 Columns 数据
				List<Map<String, String>> bodyColumns = List.of(
						Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
						Map.of("Name", "STATUS", "DataType", "S", "Caption", "操作标记"),
						Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
						Map.of("Name", "WORK_TIME", "DataType", "S", "Caption", "确认时间"),
						Map.of("Name", "REC_REVISOR", "DataType", "S", "Caption", "操作人"),
						Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "车号"),
						Map.of("Name", "REASON_CODE", "DataType", "S", "Caption", "原因码"),
						Map.of("Name", "REASON", "DataType", "S", "Caption", "原因"),
						Map.of("Name", "REPAIR_TRACK", "DataType", "S", "Caption", "入修地点")
				);

				TblXdJxchsd xdJxchsd = tblXdJxchsdDao.selectVehicleData(idN[i]);

				// BODY 表的 Rows 数据
				List<List<Object>> bodyRows = List.of(
						List.of("I", 1, idN[i], formattedDate, userName, xdJxchsd.getWagonno(), 1, "", xdJxchsd.getRepairLineCode())
				);


				// 构建 Tables 数据
				List<Map<String, Object>> tables = List.of(
						Map.of("Name", "BODY", "Columns", bodyColumns, "Rows", bodyRows)
				);


				String json = createJson(sysInfo, tables);
				logger.info("@@@@@@@@@@@@@@@" + json);
//					String s1 = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json);
				String s1 = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json);

			}else {
				throw new SQLException(text(map.get("O_MESS").toString()));

		}
// 成功的逻辑，如果不需要任何其他处理，可以去掉


		}
	}

	@Transactional(rollbackFor = Exception.class)
	public void removeDataInfo(String ids, String type_LC, HttpServletRequest request) throws Exception {
		String I_IP_ADDR = request.getRemoteHost(); // 取IP
		String I_USERCODE = UserUtils.getUser().getUserCode(); // 取用户id
		String I_USERNAME = UserUtils.getUser().getUserName(); //用户名
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String[] idN = ids.split(",");
		int type = 0;
		for (int i = 0; i < idN.length; i++) {

			HashMap<String, Object> map = new HashMap<>();
			map.put("I_JXCBH", idN[i]);    // rec_id
			map.put("I_FLAG", type_LC);    // /* 1列检调度确认 2 车站确认 3撤销*/
			map.put("I_USERCODE", userId); //登录用户
			map.put("I_USERNAME", userName); //登录用户
			map.put("I_IP", I_IP_ADDR); // 本机IP地址
			try {
				cancelData(map);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			String flag = map.get("O_FLAG").toString();
			if (flag.equals("0")) {
				//成功
				long timestamp = System.currentTimeMillis();
				// 将时间戳转换为 Date 对象
				Date date = new Date(timestamp);

				// 使用 SimpleDateFormat 格式化时间戳为 yyyyMMddHHmmss 格式的字符串
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
				String formattedDate = sdf.format(date);
				String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
				// SysInfo 数据
				Map<String, Object> sysInfo = Map.of(
						"Flag", 0,
						"Msg", "",
						"SvcName", "NEM216",
						"UUID", timestampWithLast4Millis
				);

				// BODY 表的 Columns 数据
				List<Map<String, String>> bodyColumns = List.of(
						Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
						Map.of("Name", "STATUS", "DataType", "S", "Caption", "操作标记"),
						Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
						Map.of("Name", "WORK_TIME", "DataType", "S", "Caption", "确认时间"),
						Map.of("Name", "REC_REVISOR", "DataType", "S", "Caption", "操作人"),
						Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "车号"),
						Map.of("Name", "REASON_CODE", "DataType", "S", "Caption", "原因码"),
						Map.of("Name", "REASON", "DataType", "S", "Caption", "原因"),
						Map.of("Name", "REPAIR_TRACK", "DataType", "S", "Caption", "入修地点")
				);

				TblXdJxchsd xdJxchsd = tblXdJxchsdDao.selectVehicleData(idN[i]);

				// BODY 表的 Rows 数据
				List<List<Object>> bodyRows = List.of(
						List.of("D", 1, idN[i], formattedDate, userName, xdJxchsd.getWagonno(), 0, "", xdJxchsd.getRepairLineCode())
				);


				// 构建 Tables 数据
				List<Map<String, Object>> tables = List.of(
						Map.of("Name", "BODY", "Columns", bodyColumns, "Rows", bodyRows)
				);


				String json = createJson(sysInfo, tables);
				logger.info("@@@@@@@@@@@@@@@" + json);
//					String s1 = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json);
				String s1 = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json);
//					logger.info("@@@@@@@@@@@@@@@" + s1);


				TblXdJxchsd tblXdJxchsd = selectVehicleData(idN[i]);
				TblXdLjzyjl tblXdLjzyjl = selectData(tblXdJxchsd.getLjzybh());
				String JcrName = tblXdLjzyjlDao.selectJnrName(tblXdLjzyjl.getJcrCode());


				// SysInfo 数据
				Map<String, Object> sysInfo2 = Map.of(
						"Flag", 0,
						"Msg", "",
						"SvcName", "NEM215",
						"Sender", "NE",
						"UUID", timestampWithLast4Millis
				);

				// BODY 表的 Columns 数据
				List<Map<String, String>> bodyColumns2 = List.of(
						Map.of("Name", "OPERATE_FLAG", "DataType", "S", "Caption", "操作标志"),
						Map.of("Name", "REC_ID", "DataType", "S", "Caption", "记录ID"),
						Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "铁路车号"),
						Map.of("Name", "GOODS_CODE", "DataType", "S", "Caption", "运输品名"),
						Map.of("Name", "GOODS_NAME", "DataType", "S", "Caption", "运输品名名称"),
						Map.of("Name", "MAKE_GOODS_CODE", "DataType", "S", "Caption", "制造品名代码"),
						Map.of("Name", "MAKE_GOODS_NAME", "DataType", "S", "Caption", "制造品名名称"),
						Map.of("Name", "STATION_CODE", "DataType", "S", "Caption", "当前车站"),
						Map.of("Name", "STATION_NAME", "DataType", "S", "Caption", "车站名称"),
						Map.of("Name", "YARDNO", "DataType", "S", "Caption", "当前场地"),
						Map.of("Name", "YARDNO_CNAME", "DataType", "S", "Caption", "场地名称"),
						Map.of("Name", "STATION_TRACK", "DataType", "S", "Caption", "当前股道"),
						Map.of("Name", "STATION_TRACK_CNAME", "DataType", "S", "Caption", "股道中文"),
						Map.of("Name", "NOTIFIER", "DataType", "S", "Caption", "通知人"),
						Map.of("Name", "NOTICE_TIME", "DataType", "S", "Caption", "通知时间"),
						Map.of("Name", "CAR_INSPECTOR", "DataType", "S", "Caption", "检车人"),
						Map.of("Name", "WAGON_CHECK_PERSON", "DataType", "S", "Caption", "列检人"),
						Map.of("Name", "TRAIN_INSPECTE_STIME", "DataType", "S", "Caption", "列检开始时间"),
						Map.of("Name", "FS_CODE", "DataType", "S", "Caption", "发站代码TS"),
						Map.of("Name", "ARRI_STATION_CODE", "DataType", "S", "Caption", "到站代码"),
						Map.of("Name", "ARRI_STOCK", "DataType", "S", "Caption", "到达股道"),
						Map.of("Name", "DETAIN_CAR_TYPE", "DataType", "S", "Caption", "扣车类别代码"),
						Map.of("Name", "DETAIN_CAR_TYPE_CNAME", "DataType", "S", "Caption", "扣车类别名称"),
						Map.of("Name", "ERR_CAUSE_CODE", "DataType", "S", "Caption", "故障代码"),
						Map.of("Name", "FAULT_REASON", "DataType", "S", "Caption", "故障原因_1"),
						Map.of("Name", "IN_REPAIR_TYPE", "DataType", "S", "Caption", "入修类别"),
						Map.of("Name", "IN_REPAIR_WAY", "DataType", "S", "Caption", "入修方式"),
						Map.of("Name", "TRAIN_INSPECTE_ETIME", "DataType", "S", "Caption", "列检结束时间"),
						Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")

				);

				// BODY 表的 Rows 数据
				// 处理 tblXdJxchsd 对象
				String ljzybh = tblXdJxchsd != null ? tblXdJxchsd.getLjzybh() : "";
				String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
				Date workStartTime = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getWorkStartTime()).orElse(new Date()) : new Date();
				String faultItemCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemCode()).orElse("") : "";
				String faultItemName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultItemName()).orElse("") : "";
				String faultCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultCode()).orElse("") : "";
				String faultName = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getFaultName()).orElse("") : "";
				String repairMethodCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodCode()).orElse("") : "";
				String repairMethodDetailCode = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRepairMethodDetailCode()).orElse("") : "";
				String remark = tblXdJxchsd != null ? Optional.ofNullable(tblXdJxchsd.getRemark()).orElse("") : "";
// 处理 tblXdLjzyjl 对象
				String stationUsername = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationUsername()).orElse("") : "";
				Date stationTime = tblXdLjzyjl != null ? Optional.ofNullable(tblXdLjzyjl.getStationTime()).orElse(new Date()) : new Date();
				String lineCodeFirstTwo = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getArriveStationCode()).map(code -> code.length() >= 2 ? code.substring(0, 2) : "").orElse("") : "";
				String lineCode = tblXdLjzyjl != null ? Optional.ofNullable(tblXdJxchsd.getRepairLineCode()).orElse("") : "";

// 构建 bodyRows2 列表
				List<List<Object>> bodyRows2 = List.of(
						List.of(
								"D",
								idN[i],
								wagonno,
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								"",
								stationUsername,
								stationTime,
								JcrName,
								userName,
								workStartTime,
								"",
								lineCodeFirstTwo,
								lineCode,
								faultItemCode,
								faultItemName,
								faultCode,
								faultName,
								repairMethodCode,
								repairMethodDetailCode,
								"",
								remark
						)
				);


				//构建 Tables 数据
				List<Map<String, Object>> tables2 = List.of(
						Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2)
				);


				String json2 = createJson(sysInfo2, tables2);
				logger.info("@@@@@@@@@@@@@@@" + json2);

//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
				String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
//					logger.info("####################################"+result);


			}
			else{
				throw new SQLException(text(map.get("O_MESS").toString()));
			}
		}
	}

	@Transactional(rollbackFor = Exception.class)
	public void sendInfo(String jhhString, HttpServletRequest request) throws Exception {
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String[] jhharray = jhhString.split("\\^");
		long timestamp = System.currentTimeMillis();
		String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
		for (String s : jhharray) {
			TblXdJxchsd tblXdJxchsd = selectVehicleData(s);
			// 定义日期格式
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

			// 解析字符串为 java.util.Date
			java.util.Date parsedDate = dateFormat.parse(String.valueOf(timestamp));
			// 获取当前日期和时间
			Date now = new Date();

			// 格式化当前日期和时间
			String formattedDate = dateFormat.format(now);

			// SysInfo 数据
			Map<String, Object> sysInfo2 = Map.of(
					"Flag", 0,
					"Msg", "",
					"SvcName", "NEM217",
					"Sender", "NE",
					"UUID", timestampWithLast4Millis
			);

			// BODY 表的 Columns 数据
			List<Map<String, String>> bodyColumns2 = List.of(
					Map.of("Name", "OPERATION_FLAG", "DataType", "S", "Caption", "操作标志"),
					Map.of("Name", "ITEM_CODE", "DataType", "S", "Caption", "偏重"),
					Map.of("Name", "REC_REVISOR", "DataType", "S", "Caption", "操作人"),
					Map.of("Name", "WORK_TIME", "DataType", "S", "Caption", "操作时间")


			);
			// 处理 tblXdJxchsd 对象
			String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
// 构建 bodyRows2 列表
			List<List<Object>> bodyRows2 = List.of(
					List.of(
							"I",
							1,
							userName,
							formattedDate
					)
			);

			// DETAIL 表的 Columns 数据
			List<Map<String, String>> detailColumns = List.of(
					Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "车号"),
					Map.of("Name", "IS_NOPEAK", "DataType", "S", "Caption", "是否禁峰"),
					Map.of("Name", "SPEED_LIMIT", "DataType", "S", "Caption", "限速"),
					Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")
			);
			// DETAIL 表的 Rows 数据
			List<List<Object>> detailRows = new ArrayList<>();
			List<Object> newRow = new ArrayList<>();
			newRow.add(wagonno);
			newRow.add("");
			newRow.add("");
			newRow.add("");
			detailRows.add(newRow);
			//构建 Tables 数据
			List<Map<String, Object>> tables2 = List.of(
					Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2),
					Map.of("Name", "DETAIL", "Columns", detailColumns, "Rows", detailRows)
			);
			String json2 = createJson(sysInfo2, tables2);

//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
			String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
			logger.info("####################################" + result);
			updateFocusArea(s, userName, userId,"I",tblXdJxchsd);
		}


	}


	@Transactional(rollbackFor = Exception.class)
	public void sendInfo1(TblXdJxchsd tblXdJxchsd, HttpServletRequest request) throws Exception {
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String[] jhharray = tblXdJxchsd.getIds().split(",");
		long timestamp = System.currentTimeMillis();
		String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
		String isNopeak = tblXdJxchsd.getIsNopeak();
		String speedLimit = tblXdJxchsd.getSpeedLimit();
		String remark = tblXdJxchsd.getRemark();

		for (String s : jhharray) {
			 tblXdJxchsd = selectVehicleData(s);
			// 定义日期格式
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

			// 解析字符串为 java.util.Date
			java.util.Date parsedDate = dateFormat.parse(String.valueOf(timestamp));
			// 获取当前日期和时间
			Date now = new Date();

			// 格式化当前日期和时间
			String formattedDate = dateFormat.format(now);

			// SysInfo 数据
			Map<String, Object> sysInfo2 = Map.of(
					"Flag", 0,
					"Msg", "",
					"SvcName", "NEM217",
					"Sender", "NE",
					"UUID", timestampWithLast4Millis
			);

			// BODY 表的 Columns 数据
			List<Map<String, String>> bodyColumns2 = List.of(
					Map.of("Name", "OPERATION_FLAG", "DataType", "S", "Caption", "操作标志"),
					Map.of("Name", "ITEM_CODE", "DataType", "S", "Caption", "偏重"),
					Map.of("Name", "REC_REVISOR", "DataType", "S", "Caption", "操作人"),
					Map.of("Name", "WORK_TIME", "DataType", "S", "Caption", "操作时间")

			);
			// 处理 tblXdJxchsd 对象
			String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
// 构建 bodyRows2 列表
			List<List<Object>> bodyRows2 = List.of(
					List.of(
							"I",
							1,
							userName,
							formattedDate
					)
			);

			// DETAIL 表的 Columns 数据
			List<Map<String, String>> detailColumns = List.of(
					Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "车号"),
					Map.of("Name", "IS_NOPEAK", "DataType", "S", "Caption", "是否禁峰"),
					Map.of("Name", "SPEED_LIMIT", "DataType", "S", "Caption", "限速"),
					Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")
			);
			// DETAIL 表的 Rows 数据
			List<List<Object>> detailRows = new ArrayList<>();
			List<Object> newRow = new ArrayList<>();
			newRow.add(wagonno);
			newRow.add(isNopeak);
			newRow.add(speedLimit);
			newRow.add(remark);
			detailRows.add(newRow);
			//构建 Tables 数据
			List<Map<String, Object>> tables2 = List.of(
					Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2),
					Map.of("Name", "DETAIL", "Columns", detailColumns, "Rows", detailRows)
			);
			String json2 = createJson(sysInfo2, tables2);

//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
			String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
			logger.info("####################################" + result);
			updateFocusArea(s, userName, userId,"I",tblXdJxchsd);
			tblXdJxchsdDao.updateRemark(s,isNopeak,speedLimit,remark);
		}


	}



	private void updateFocusArea(String s, String userName, String userId,String Flag,TblXdJxchsd tblXdJxchsd)  {
		long timeMillis = System.currentTimeMillis();
		// 将时间戳转换为 java.util.Date
		Date date = new Date(timeMillis);

		if ("I".equals(Flag)){
			tblXdJxchsdDao.updateFocusArea(s, "1");
			tblXdJxchsdDao.insertFocusArea(s, userName, userId,date,
					tblXdJxchsd.getGoodsName(),tblXdJxchsd.getLine(),tblXdJxchsd.getLineCode(),date,tblXdJxchsd.getWagonno());
		}else{
			tblXdJxchsdDao.updateFocusArea(s, "0");
			tblXdJxchsdDao.endFocusArea(s, userName, userId,date,
					tblXdJxchsd.getGoodsName(),tblXdJxchsd.getLine(),tblXdJxchsd.getLineCode(),date,tblXdJxchsd.getWagonno());
		}


	}

	@Transactional(rollbackFor = Exception.class)
	public void backInfo(String jhhString, HttpServletRequest request) throws Exception {
		String userId = JsonGenerator.extractAndDecodeAccessToken(request);
		logger.info("9999999999999999999999+_____" + userId);
		String userName = tblZdWorkerdzDao.selectName1(userId);
		String[] jhharray = jhhString.split("\\^");
		long timestamp = System.currentTimeMillis();
		String timestampWithLast4Millis = timestamp + String.format("%04d", timestamp % 10000);
		for (String s : jhharray) {
			TblXdJxchsd tblXdJxchsd = selectVehicleData(s);
			// 定义日期格式
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			// 获取当前日期和时间
			Date now = new Date();

			// 格式化当前日期和时间
			String formattedDate = dateFormat.format(now);

			// 解析字符串为 java.util.Date
			java.util.Date parsedDate = dateFormat.parse(String.valueOf(timestamp));

			// SysInfo 数据
			Map<String, Object> sysInfo2 = Map.of(
					"Flag", 0,
					"Msg", "",
					"SvcName", "NEM217",
					"Sender", "NE",
					"UUID", timestampWithLast4Millis
			);

			// BODY 表的 Columns 数据
			List<Map<String, String>> bodyColumns2 = List.of(
					Map.of("Name", "OPERATION_FLAG", "DataType", "S", "Caption", "操作标志"),
					Map.of("Name", "ITEM_CODE", "DataType", "S", "Caption", "偏重"),
					Map.of("Name", "REC_REVISOR", "DataType", "S", "Caption", "操作人"),
					Map.of("Name", "WORK_TIME", "DataType", "S", "Caption", "操作时间")

			);


			// 处理 tblXdJxchsd 对象
			String wagonno = tblXdJxchsd != null ? tblXdJxchsd.getWagonno() : "";
			List<List<Object>> bodyRows2 = List.of(
					List.of(
							"D",
							1,
							userName,
							formattedDate
					)
			);
			// DETAIL 表的 Columns 数据
			List<Map<String, String>> detailColumns = List.of(
					Map.of("Name", "WAGONNO", "DataType", "S", "Caption", "车号"),
					Map.of("Name", "IS_NOPEAK", "DataType", "S", "Caption", "是否禁峰"),
					Map.of("Name", "SPEED_LIMIT", "DataType", "S", "Caption", "限速"),
					Map.of("Name", "REMARK", "DataType", "S", "Caption", "备注")
			);
			// DETAIL 表的 Rows 数据
			List<List<Object>> detailRows = new ArrayList<>();
			List<Object> newRow = new ArrayList<>();
			newRow.add(wagonno);
			newRow.add("");
			newRow.add("");
			newRow.add("");
			detailRows.add(newRow);
			//构建 Tables 数据
			List<Map<String, Object>> tables2 = List.of(
					Map.of("Name", "BODY", "Columns", bodyColumns2, "Rows", bodyRows2),
					Map.of("Name", "DETAIL", "Columns", detailColumns, "Rows", detailRows)
			);
			String json2 = createJson(sysInfo2, tables2);

//					String result = sendJsonWithHttpClient("172.16.16.36", 8085, "/lj", json2);
			String result = sendJsonWithHttpClient(serverTrexConfig.getAddress(), serverTrexConfig.getPort(), serverTrexConfig.getMethod(), json2);
			logger.info("####################################" + result);
			updateFocusArea(s, userName, userId,"D",tblXdJxchsd);
		}


	}
}


